#include <iostream>
#include <string>
#include <cstring>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

using std::string;
using std::endl ;
using std::cout;


class Name_Pipe
{
public:
    Name_Pipe(const std::string& path_name , int mode)
    :path_name_(path_name) , mode_(mode)
    {
        // 创建管道文件
        int n = mkfifo(path_name_.c_str() , mode_);
        if(n < 0) 
        {
            cout << "mkfifo error : message " << strerror(errno) << endl; 
            exit(-1);
        }
    }
    ~Name_Pipe()
    {
        // 关闭管道文件
        int n = unlink(path_name_.c_str());
        if(n < 0)
        {
            cout << "unlink error : message " << strerror(errno) << endl; 
            exit(-1);
        }
    }
private:
    std::string path_name_;      // 管道名称
    int mode_;                    // 管道权限
};
